package com.xkdx.caipiao.presistence.bank;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.presistence.identity.IdentityInfo;

public class GetBundleBanksModule extends AbsModule {
	public BankInfo info;
	public IdentityInfo baseinfo;
	public  boolean isSuccess = false;
	public String message="";
	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;
			for (int i = 0; i < backJson.size(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				message=jsonObj.getString("Message");
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("MainInfoGet")) {
					parseIdentity(jsonObj.getJSONObject("DetailInfo"));
				}
				else if (sortOfAct.equals("getBindBankList")) {
					parseBankList(jsonObj.getJSONArray("DetailInfo"));
				}
			}
		} catch (Exception e) {
			
			throw e;
		}
	}
	
	private void parseIdentity(JSONObject person) throws Exception {
		try {
			baseinfo = new IdentityInfo();
			baseinfo.setCardtype(person.getString("cardtype"));
			baseinfo.setCash(person.getString("cash"));
			baseinfo.setId(person.getString("id"));
			baseinfo.setIdcard(person.getString("idcard"));
			baseinfo.setPhone(person.getString("phone"));
			baseinfo.setRealname(person.getString("realname"));
			baseinfo.setVertify(person.getString("vertify"));
			isSuccess=true;
		} catch (Exception e) {
			isSuccess=false;
			throw e;
		}
	}
	

	private void parseBankList(JSONArray person) throws Exception {
		try {

			info = new BankInfo();
			List<BankItemInfo> list = new ArrayList<BankItemInfo>();
			for (int i = 0; i < person.size(); i++) {
				BankItemInfo item = new BankItemInfo();
				JSONObject obj = person.getJSONObject(i);
				item.setBankicon(obj.getString(BankItemInfo.BANKICON));
				item.setBankname(obj.getString(BankItemInfo.BANKNAME));
				item.setCardid(obj.getString(BankItemInfo.CARDID));
				item.setDefitem(obj.getString(BankItemInfo.DEFITEM));
				item.setId(obj.getString(BankItemInfo.ID));
				item.setType(obj.getString(BankItemInfo.TYPE));
				item.setUid(obj.getString(BankItemInfo.UID));
				list.add(item);
			}
			info.setList(list);
			isSuccess=true;
		} catch (Exception e) {
			isSuccess=false;
			throw e;
		}
	}

}
